package com.atguigu.juc.day04.cf;

import com.atguigu.juc.day04.pool.Demo01MyPool;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;

public class Demo09SupplyThenApply {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ExecutorService executorService = Demo01MyPool.getExecutorService();

        // thenApply() 方法：接收前面任务的返回值，并且当前任务也有返回值
        String finalTaskResult = CompletableFuture
                .supplyAsync(() -> "first task result", executorService)
                .thenApply(prevTaskResult -> {
                    System.out.println("prevTaskResult = " + prevTaskResult);
                    return "second task result";
                }).get();

        System.out.println("finalTaskResult = " + finalTaskResult);

    }

}
